home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 2.iso / dist / fw_gnats.idb / usr / freeware / bin / send-pr.z / send-pr
Text File  |  1999-04-16  |  14KB  |  520 lines

  1. #!/bin/sh
  2. # Submit a problem report to a GNATS site.
  3. # Copyright (C) 1993 Free Software Foundation, Inc.
  4. # Contributed by Brendan Kehoe (brendan@cygnus.com), based on a
  5. # version written by Heinz G. Seidl (hgs@ide.com).
  6. #
  7. # This file is part of GNU GNATS.
  8. #
  9. # GNU GNATS is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2, or (at your option)
  12. # any later version.
  13. #
  14. # GNU GNATS is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with GNU GNATS; see the file COPYING.  If not, write to
  21. # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23. # The version of this send-pr.
  24. VERSION=3.2
  25.  
  26. # The submitter-id for your site.
  27. SUBMITTER=humu
  28.  
  29. # Where the GNATS directory lives, if at all.
  30. [ -z "$GNATS_ROOT" ] && 
  31. GNATS_ROOT=/usr/freeware/lib/gnats/gnats-db
  32.  
  33. # The default mail address for PR submissions. 
  34. GNATS_ADDR=bugs
  35.  
  36. # Where the gnats category tree lives.
  37. DATADIR=/usr/freeware/lib
  38.  
  39. # If we've been moved around, try using GCC_EXEC_PREFIX.
  40. [ ! -d $DATADIR/gnats -a -d "$GCC_EXEC_PREFIX" ] && DATADIR=${GCC_EXEC_PREFIX}..
  41.  
  42. # The default release for this host.
  43. DEFAULT_RELEASE="unknown-1.0"
  44.  
  45. # The default organization.
  46. DEFAULT_ORGANIZATION="humu"
  47.  
  48. # The default site to look for.
  49. GNATS_SITE=humu
  50.  
  51. # Newer config information?
  52. [ -f ${GNATS_ROOT}/gnats-adm/config ] && . ${GNATS_ROOT}/gnats-adm/config
  53.  
  54. # What mailer to use.  This must come after the config file, since it is
  55. # host-dependent.
  56. MAIL_AGENT="/usr/lib/sendmail -oi -t"
  57.  
  58. ECHON=bsd
  59.  
  60. if [ $ECHON = bsd ] ; then
  61.   ECHON1="echo -n"
  62.   ECHON2=
  63. elif [ $ECHON = sysv ] ; then
  64.   ECHON1=echo
  65.   ECHON2='\c'
  66. else
  67.   ECHON1=echo
  68.   ECHON2=
  69. fi
  70.  
  71. #
  72.  
  73. [ -z "$TMPDIR" ] && TMPDIR=/tmp
  74.  
  75. TEMP=$TMPDIR/p$$
  76. BAD=$TMPDIR/pbad$$
  77. REF=$TMPDIR/pf$$
  78.  
  79. if [ -z "$LOGNAME" -a -n "$USER" ]; then
  80.   LOGNAME=$USER
  81. fi
  82.  
  83. FROM="$LOGNAME"
  84. REPLY_TO="$LOGNAME"
  85.  
  86. # Find out the name of the originator of this PR.
  87. if [ -n "$NAME" ]; then
  88.   ORIGINATOR="$NAME"
  89. elif [ -f $HOME/.fullname ]; then
  90.   ORIGINATOR="`sed -e '1q' $HOME/.fullname`"
  91. elif [ -f /bin/domainname ]; then
  92.   if [ "`/bin/domainname`" != "" -a -f /usr/bin/ypcat ]; then
  93.     # Must use temp file due to incompatibilities in quoting behavior
  94.     # and to protect shell metacharacters in the expansion of $LOGNAME
  95.     /usr/bin/ypcat passwd 2>/dev/null | cat - /etc/passwd | grep "^$LOGNAME:" |
  96.       cut -f5 -d':' | sed -e 's/,.*//' > $TEMP
  97.     ORIGINATOR="`cat $TEMP`"
  98.     rm -f $TEMP
  99.   fi
  100. fi
  101.  
  102. if [ "$ORIGINATOR" = "" ]; then
  103.   grep "^$LOGNAME:" /etc/passwd | cut -f5 -d':' | sed -e 's/,.*//' > $TEMP
  104.   ORIGINATOR="`cat $TEMP`"
  105.   rm -f $TEMP
  106. fi
  107.  
  108. if [ -n "$ORGANIZATION" ]; then
  109.   if [ -f "$ORGANIZATION" ]; then
  110.     ORGANIZATION="`cat $ORGANIZATION`"
  111.   fi
  112. else
  113.   if [ -n "$DEFAULT_ORGANIZATION" ]; then
  114.     ORGANIZATION="$DEFAULT_ORGANIZATION"
  115.   elif [ -f $HOME/.organization ]; then
  116.     ORGANIZATION="`cat $HOME/.organization`"
  117.   elif [ -f $HOME/.signature ]; then
  118.     ORGANIZATION="`cat $HOME/.signature`"
  119.   fi
  120. fi
  121.  
  122. # If they don't have a preferred editor set, then use
  123. if [ -z "$VISUAL" ]; then
  124.   if [ -z "$EDITOR" ]; then
  125.     EDIT=vi
  126.   else
  127.     EDIT="$EDITOR"
  128.   fi
  129. else
  130.   EDIT="$VISUAL"
  131. fi
  132.  
  133. # Find out some information.
  134. SYSTEM=`( [ -f /bin/uname ] && /bin/uname -a ) || \
  135.         ( [ -f /usr/bin/uname ] && /usr/bin/uname -a ) || echo ""`
  136. ARCH=`[ -f /bin/arch ] && /bin/arch`
  137. MACHINE=`[ -f /bin/machine ] && /bin/machine`
  138.  
  139. COMMAND=`echo $0 | sed -e 's,.*/,,'`
  140. USAGE="Usage: $COMMAND [-PVL] [-t address] [-f filename] [--request-id] 
  141. [--version]"
  142. REMOVE=
  143. BATCH=
  144.  
  145. while [ $# -gt 0 ]; do
  146.   case "$1" in
  147.     -r) ;;         # Ignore for backward compat.
  148.     -t | --to) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
  149.     shift ; GNATS_ADDR="$1"
  150.     EXPLICIT_GNATS_ADDR=true
  151.         ;;
  152.     -f | --file) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
  153.     shift ; IN_FILE="$1"
  154.     if [ "$IN_FILE" != "-" -a ! -r "$IN_FILE" ]; then
  155.       echo "$COMMAND: cannot read $IN_FILE"
  156.       exit 1
  157.     fi
  158.     ;;
  159.     -b | --batch) BATCH=true ;;
  160.     -p | -P | --print) PRINT=true ;;
  161.     -L | --list) FORMAT=norm ;;
  162.     -l | -CL | --lisp) FORMAT=lisp ;;
  163.     --request-id) REQUEST_ID=true ;;
  164.     -h | --help) echo "$USAGE"; exit 0 ;;
  165.     -V | --version) echo "$VERSION"; exit 0 ;;
  166.     -*) echo "$USAGE" ; exit 1 ;;
  167.     *) if [ -z "$USER_GNATS_SITE" ]; then
  168.      if [ ! -r "$DATADIR/gnats/$1" ]; then
  169.        echo "$COMMAND: the GNATS site $1 does not have a categories list."
  170.        exit 1
  171.      else
  172.        # The site name is the alias they'll have to have created.
  173.        USER_GNATS_SITE=$1
  174.      fi
  175.        else
  176.      echo "$USAGE" ; exit 1
  177.        fi
  178.        ;;
  179.  esac
  180.  shift
  181. done
  182.  
  183. if [ -n "$USER_GNATS_SITE" ]; then
  184.   GNATS_SITE=$USER_GNATS_SITE
  185.   GNATS_ADDR=$USER_GNATS_SITE-gnats
  186. fi
  187.  
  188. if [ "$SUBMITTER" = "unknown" -a -z "$REQUEST_ID" -a -z "$IN_FILE" ]; then
  189.   cat << '__EOF__'
  190. It seems that send-pr is not installed with your unique submitter-id.
  191. You need to run
  192.  
  193.           install-sid YOUR-SID
  194.  
  195. where YOUR-SID is the identification code you received with `send-pr'.
  196. `send-pr' will automatically insert this value into the template field
  197. `>Submitter-Id'.  If you've downloaded `send-pr' from the Net, use `net'
  198. for this value.  If you do not know your id, run `send-pr --request-id' to 
  199. get one from your support site.
  200. __EOF__
  201.   exit 1
  202. fi
  203.  
  204. if [ -r "$DATADIR/gnats/$GNATS_SITE" ]; then
  205.   CATEGORIES=`grep -v '^#' $DATADIR/gnats/$GNATS_SITE | sort`
  206. else
  207.   echo "$COMMAND: could not read $DATADIR/gnats/$GNATS_SITE for categories list."
  208.   exit 1
  209. fi
  210.  
  211. if [ -z "$CATEGORIES" ]; then
  212.   echo "$COMMAND: the categories list for $GNATS_SITE was empty!"
  213.   exit 1
  214. fi
  215.  
  216. case "$FORMAT" in
  217.   lisp) echo "$CATEGORIES" | \
  218.         awk 'BEGIN {printf "( "} {printf "(\"%s\") ",$0} END {printf ")\n"}'
  219.         exit 0
  220.         ;;
  221.   norm) l=`echo "$CATEGORIES" | \
  222.     awk 'BEGIN {max = 0; } { if (length($0) > max) { max = length($0); } }
  223.          END {print max + 1;}'`
  224.     c=`expr 70 / $l`
  225.     if [ $c -eq 0 ]; then c=1; fi
  226.     echo "$CATEGORIES" | \
  227.         awk 'BEGIN {print "Known categories:"; i = 0 }
  228.           { printf ("%-'$l'.'$l's", $0); if ((++i % '$c') == 0) { print "" } }
  229.             END { print ""; }'
  230.         exit 0
  231.         ;;
  232. esac
  233.  
  234. ORIGINATOR_C='<name of the PR author (one line)>'
  235. ORGANIZATION_C='<organization of PR author (multiple lines)>'
  236. CONFIDENTIAL_C='<[ yes | no ] (one line)>'
  237. SYNOPSIS_C='<synopsis of the problem (one line)>'
  238. SEVERITY_C='<[ non-critical | serious | critical ] (one line)>'
  239. PRIORITY_C='<[ low | medium | high ] (one line)>'
  240. CATEGORY_C='<name of the product (one line)>'
  241. CLASS_C='<[ sw-bug | doc-bug | change-request | support ] (one line)>'
  242. RELEASE_C='<release number or tag (one line)>'
  243. ENVIRONMENT_C='<machine, os, target, libraries (multiple lines)>'
  244. DESCRIPTION_C='<precise description of the problem (multiple lines)>'
  245. HOW_TO_REPEAT_C='<code/input/activities to reproduce the problem (multiple lines)>'
  246. FIX_C='<how to correct or work around the problem, if known (multiple lines)>'
  247.  
  248. # Catch some signals. ($xs kludge needed by Sun /bin/sh)
  249. xs=0
  250. trap 'rm -f $REF $TEMP; exit $xs' 0
  251. trap 'echo "$COMMAND: Aborting ..."; rm -f $REF $TEMP; xs=1; exit' 1 2 3 13 15
  252.  
  253. # If they told us to use a specific file, then do so.
  254. if [ -n "$IN_FILE" ]; then
  255.   if [ "$IN_FILE" = "-" ]; then
  256.     # The PR is coming from the standard input.
  257.     if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
  258.       sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" > $TEMP
  259.     else
  260.       cat > $TEMP
  261.     fi
  262.   else
  263.     # Use the file they named.
  264.     if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
  265.       sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" $IN_FILE > $TEMP
  266.     else
  267.       cat $IN_FILE > $TEMP
  268.     fi
  269.   fi
  270. else
  271.  
  272.   if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
  273.     # If their PR_FORM points to a bogus entry, then bail.
  274.     if [ ! -f "$PR_FORM" -o ! -r "$PR_FORM" -o ! -s "$PR_FORM" ]; then
  275.       echo "$COMMAND: can't seem to read your template file (\`$PR_FORM'), ignoring PR_FORM"
  276.       sleep 1
  277.       PRINT_INTERN=bad_prform
  278.     fi
  279.   fi
  280.  
  281.   if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
  282.     cp $PR_FORM $TEMP || 
  283.       ( echo "$COMMAND: could not copy $PR_FORM" ; xs=1; exit )
  284.   else
  285.     for file in $TEMP $REF ; do
  286.       cat  > $file << '__EOF__'
  287. SEND-PR: -*- send-pr -*-
  288. SEND-PR: Lines starting with `SEND-PR' will be removed automatically, as
  289. SEND-PR: will all comments (text enclosed in `<' and `>').
  290. SEND-PR: 
  291. SEND-PR: Please consult the send-pr man page `send-pr(1)' or the Texinfo
  292. SEND-PR: manual if you are not sure how to fill out a problem report.
  293. SEND-PR:
  294. SEND-PR: Choose from the following categories:
  295. SEND-PR:
  296. __EOF__
  297.  
  298.       # Format the categories so they fit onto lines.
  299.     l=`echo "$CATEGORIES" | \
  300.     awk 'BEGIN {max = 0; } { if (length($0) > max) { max = length($0); } }
  301.          END {print max + 1;}'`
  302.     c=`expr 61 / $l`
  303.     if [ $c -eq 0 ]; then c=1; fi
  304.     echo "$CATEGORIES" | \
  305.         awk 'BEGIN {printf "SEND-PR: "; i = 0 }
  306.           { printf ("%-'$l'.'$l's", $0);
  307.         if ((++i % '$c') == 0) { printf "\nSEND-PR: " } }
  308.             END { printf "\nSEND-PR:\n"; }' >> $file
  309.  
  310.       cat >> $file << __EOF__
  311. To: $GNATS_ADDR
  312. Subject: 
  313. From: $FROM
  314. Reply-To: $REPLY_TO
  315. X-send-pr-version: $VERSION
  316.  
  317.  
  318. >Submitter-Id:   $SUBMITTER
  319. >Originator:      $ORIGINATOR
  320. >Organization:
  321. `
  322.   if [ -n "$ORGANIZATION" ]; then
  323.     echo "$ORGANIZATION"
  324.   else
  325.     echo "    $ORGANIZATION_C" ;
  326.   fi ;
  327. `
  328. >Confidential:  $CONFIDENTIAL_C
  329. >Synopsis:    $SYNOPSIS_C
  330. >Severity:    $SEVERITY_C
  331. >Priority:    $PRIORITY_C
  332. >Category:     $CATEGORY_C
  333. >Class:        $CLASS_C
  334. >Release:     `if [ -n "$DEFAULT_RELEASE" ]; then
  335.            echo "$DEFAULT_RELEASE"
  336.           else
  337.            echo "    $RELEASE_C"
  338.           fi; `
  339. >Environment:
  340.         $ENVIRONMENT_C
  341. `[ -n "$SYSTEM" ] && echo System: $SYSTEM`
  342. `[ -n "$ARCH" ] && echo Architecture: $ARCH`
  343. `[ -n "$MACHINE" ] && echo Machine: $MACHINE`
  344. >Description:
  345.     $DESCRIPTION_C
  346. >How-To-Repeat:
  347.     $HOW_TO_REPEAT_C
  348. >Fix:
  349.     $FIX_C
  350. __EOF__
  351.     done
  352.   fi
  353.  
  354.   if [ "$PRINT" = true -o "$PRINT_INTERN" = true ]; then
  355.     cat $TEMP
  356.     xs=0; exit
  357.   fi
  358.  
  359.   chmod u+w $TEMP
  360.   if [ -z "$REQUEST_ID" ]; then
  361.     eval $EDIT $TEMP
  362.   else
  363.     ed -s $TEMP << '__EOF__'
  364. /^Subject/s/^Subject:.*/Subject: request for a customer id/
  365. /^>Category/s/^>Category:.*/>Category: send-pr/
  366. w
  367. q
  368. __EOF__
  369.   fi
  370.  
  371.   if cmp -s $REF $TEMP ; then
  372.     echo "$COMMAND: problem report not filled out, therefore not sent"
  373.     xs=1; exit
  374.   fi
  375. fi
  376.  
  377. #
  378. #    Check the enumeration fields
  379.  
  380. # This is a "sed-subroutine" with one keyword parameter 
  381. # (with workaround for Sun sed bug)
  382. #
  383. SED_CMD='
  384. /$PATTERN/{
  385. s|||
  386. s|<.*>||
  387. s|^[     ]*||
  388. s|[     ]*$||
  389. p
  390. q
  391. }'
  392.  
  393.  
  394. while [ -z "$REQUEST_ID" ]; do
  395.   CNT=0
  396.  
  397.   # 1) Confidential
  398.   #
  399.   PATTERN=">Confidential:"
  400.   CONFIDENTIAL=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
  401.   case "$CONFIDENTIAL" in
  402.     ""|yes|no) CNT=`expr $CNT + 1` ;;
  403.     *) echo "$COMMAND: \`$CONFIDENTIAL' is not a valid value for \`Confidential'." ;;
  404.   esac
  405.   #
  406.   # 2) Severity
  407.   #
  408.   PATTERN=">Severity:"
  409.   SEVERITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
  410.   case "$SEVERITY" in
  411.     ""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
  412.     *)  echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'."
  413.   esac
  414.   #
  415.   # 3) Priority
  416.   #
  417.   PATTERN=">Priority:"
  418.   PRIORITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
  419.   case "$PRIORITY" in
  420.     ""|low|medium|high) CNT=`expr $CNT + 1` ;;
  421.     *)  echo "$COMMAND: \`$PRIORITY' is not a valid value for \`Priority'."
  422.   esac
  423.   #
  424.   # 4) Category
  425.   #
  426.   PATTERN=">Category:"
  427.   CATEGORY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
  428.   FOUND=
  429.   for C in $CATEGORIES
  430.   do
  431.     if [ "$C" = "$CATEGORY" ]; then FOUND=true ; break ; fi
  432.   done
  433.   if [ -n "$FOUND" ]; then
  434.     CNT=`expr $CNT + 1`    
  435.   else
  436.     if [ -z "$CATEGORY" ]; then
  437.       echo "$COMMAND: you must include a Category: field in your report."
  438.     else
  439.       echo "$COMMAND: \`$CATEGORY' is not a known category."
  440.     fi
  441.   fi
  442.   #
  443.   # 5) Class
  444.   #
  445.   PATTERN=">Class:"
  446.   CLASS=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
  447.   case "$CLASS" in
  448.     ""|sw-bug|doc-bug|change-request|support) CNT=`expr $CNT + 1` ;;
  449.     *)  echo "$COMMAND: \`$CLASS' is not a valid value for \`Class'."
  450.   esac
  451.  
  452.   [ $CNT -lt 5 -a -z "$BATCH" ] && 
  453.     echo "Errors were found with the problem report."
  454.  
  455.   while true; do
  456.     if [ -z "$BATCH" ]; then
  457.       $ECHON1 "a)bort, e)dit or s)end? $ECHON2"
  458.       read input
  459.     else
  460.       if [ $CNT -eq 5 ]; then
  461.         input=s
  462.       else
  463.         input=a
  464.       fi
  465.     fi
  466.     case "$input" in
  467.       a*)
  468.     if [ -z "$BATCH" ]; then
  469.       echo "$COMMAND: the problem report remains in $BAD and is not sent."
  470.       mv $TEMP $BAD
  471.         else
  472.       echo "$COMMAND: the problem report is not sent."
  473.     fi
  474.     xs=1; exit
  475.     ;;
  476.       e*)
  477.         eval $EDIT $TEMP
  478.     continue 2
  479.     ;;
  480.       s*)
  481.     break 2
  482.     ;;
  483.     esac
  484.   done
  485. done
  486. #
  487. #    Remove comments and send the problem report
  488. #    (we have to use patterns, where the comment contains regex chars)
  489. #
  490. # /^>Originator:/s;$ORIGINATOR;;
  491. sed  -e "
  492. /^SEND-PR:/d
  493. /^>Organization:/,/^>[A-Za-z-]*:/s;$ORGANIZATION_C;;
  494. /^>Confidential:/s;<.*>;;
  495. /^>Synopsis:/s;$SYNOPSIS_C;;
  496. /^>Severity:/s;<.*>;;
  497. /^>Priority:/s;<.*>;;
  498. /^>Category:/s;$CATEGORY_C;;
  499. /^>Class:/s;<.*>;;
  500. /^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C;;
  501. /^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C;;
  502. /^>Description:/,/^>[A-Za-z-]*:/s;$DESCRIPTION_C;;
  503. /^>How-To-Repeat:/,/^>[A-Za-z-]*:/s;$HOW_TO_REPEAT_C;;
  504. /^>Fix:/,/^>[A-Za-z-]*:/s;$FIX_C;;
  505. " $TEMP > $REF
  506.  
  507. if $MAIL_AGENT < $REF; then
  508.   echo "$COMMAND: problem report sent"
  509.   xs=0; exit
  510. else
  511.   echo "$COMMAND: mysterious mail failure."
  512.   if [ -z "$BATCH" ]; then
  513.     echo "$COMMAND: the problem report remains in $BAD and is not sent."
  514.     mv $REF $BAD
  515.   else
  516.     echo "$COMMAND: the problem report is not sent."
  517.   fi
  518.   xs=1; exit
  519. fi
  520.